﻿using System;
using System.Collections.Generic;
using System.Text;
using HZ.Supervise.IBLL;

namespace HZ.Supervise.BLL
{
	using System.Data;
	/// <summary>
	/// 新的统计功能
	/// </summary>
	public class BLL_NewStat : IBLL_NewStat
	{
		private static Dictionary<string, string> _DicCache = null;

		public static Dictionary<string, string> DicCache
		{
			get { return BLL_NewStat._DicCache; }
			set { BLL_NewStat._DicCache = value; }
		}

		private static Dictionary<string, string> _GroupCache = null;

		public static Dictionary<string, string> GroupCache
		{
			get { return BLL_NewStat._GroupCache; }
			set { BLL_NewStat._GroupCache = value; }
		}

		static BLL_NewStat()
		{
			// 以下代码自动替换默认定义的语句
			_DicCache = new Dictionary<string, string>();
			DicCache["PurchaseCountTotal"] = " SUM(PurchaseCount) AS PurchaseCountTotal"; // 采购总数
			DicCache["PurchaseAmountTotal"] = "SUM(PurchaseAmount) AS PurchaseAmountTotal"; // 采购总金额
			DicCache["DistributeRate"] = "SUM(DistributeAmount) / SUM(PurchaseAmount) AS DistributeRate"; // 配送率
			DicCache["DistributeCountTotal"] = "SUM(DistributeCount) AS DistributeCountTotal"; //配送总数
			DicCache["DistributeAmountTotal"] = "SUM(DistributeAmount) AS DistributeAmountTotal";//配送总金额
			DicCache["WareHouseCountTotal"] = "SUM(WarehouseCount) AS WareHouseCountTotal"; //入库总数
			DicCache["WareHouseRate"] = "SUM(WarehouseAmount) / SUM(PurchaseAmount) AS WareHouseRate"; //入库率
			DicCache["WareHouseAmountTotal"] = "SUM(WarehouseAmount) AS WareHouseAmountTotal"; // 入库总金额
			DicCache["PayOffAmount"] = "SUM(PayOffAmount) AS PayOffAmount"; // 付款总金额
			DicCache["ReturnedGoods"] = "SUM(ReturnAmount) AS ReturnedGoods"; // 退货总金额
			DicCache["HospitalName"] = "dbo.SelectOne(HospitalName) AS HospitalName"; // 医院名称
			DicCache["AreaName"] = "dbo.SelectOne(AreaName) AS AreaName"; // 地区名称
			DicCache["CompanyName"] = "dbo.SelectOne(CompanyName) AS CompanyName"; // 企业名称

			// 标准SQL

			// SELECT HospitalId,CompanyId_Ps,AreaId,HospitalName,AreaName,CompanyName,ReturnedGoods,PayOffAmount,WareHouseAmountTotal,WareHouseCountTotal,DistributeCountTotal,WareHouseCountTotal FROM CACHE_Stat WHERE ... Gropy By HospitalId,CompanyId_Ps,AreaId,DayTime Order By WareHouseCountTotal DESC
			// GroupCache["AreaId"] = "";
		}


		/// <summary>
		/// 医院月统计
		/// </summary>
		/// <param name="where"></param>
		/// <param name="currentpage"></param>
		/// <param name="pagesize"></param>
		/// <param name="totalrecord"></param>
		/// <returns></returns>
		public DataTable DayTime_SortSorce_GroupBy(object qeurymodel, int currentpage, int pagesize, out int totalrecord)
		{



			string sql = @"SELECT DayTime,SortSorce,SUM(PurchaseAmount) AS PurchaseAmountTotal,SUM(PurchaseCount) AS PurchaseCountTotal,
                           SUM(WarehouseAmount) AS WareHouseAmountTotal,SUM(WarehouseCount) AS WareHouseCountTotal,SUM(DistributeAmount) AS DistributeAmountTotal,
                           SUM(WarehouseAmount) / SUM  (PurchaseAmount) AS WareHouseRate FROM CACHE_STAT WHERE {0} Group By DayTime,SortSorce ORDER BY {1}";

			string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));



			HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

			des.CurrentPage = currentpage;
			totalrecord = des.TotalCount;

			return des.GetSpecailPage();

		}
		/// <summary>
		/// 单月单医院所有采购类型统计
		/// </summary>
		/// <param name="where"></param>
		/// <param name="currentpage"></param>
		/// <param name="pagesize"></param>
		/// <param name="totalrecord"></param>
		/// <returns></returns>
		public DataTable DayTime_SortSorce_GroupByForHosCurrentGoodsList(object qeurymodel, int currentpage, int pagesize, out int totalrecord)
		{
            //2011-07-30 入库率，配送率 计算方式改变 by：zhangxiong 
            string sql = @"
                            SELECT MAX(HospitalName) HospitalName,SortSorce,
                            SUM(isnull(PurchaseAmount,0)) AS PurchaseAmountTotal,
                            SUM(isnull(PurchaseCount,0)) AS PurchaseCountTotal,
                            SUM(isnull(WarehouseAmount,0)) AS WareHouseAmountTotal,
                            SUM(isnull(WarehouseCount,0)) AS WareHouseCountTotal,
                            SUM(isnull(DistributeAmount,0)) AS DistributeAmountTotal,
                            case when SUM(isnull(WarehouseAmount,0)) =0 then 0
                            when SUM(isnull(PurchaseAmount,0)) = 0 then 0
                            when convert(decimal(18,6),SUM(isnull(WarehouseAmount,0)) / SUM(isnull(PurchaseAmount,0))) >1 then 1
                            else convert(decimal(18,6),SUM(isnull(WarehouseAmount,0)) / SUM(isnull(PurchaseAmount,0))) end WarehouseRate,  
                            case when SUM(isnull(DistributeAmount,0)) = 0 then 0
                            when SUM(isnull(PurchaseAmount,0)) = 0 then 0
                            when convert(decimal(18,6),SUM(isnull(DistributeAmount,0)) / SUM(isnull(PurchaseAmount,0))) > 1 then 1
                            else convert(decimal(18,6),SUM(isnull(DistributeAmount,0)) / SUM(isnull(PurchaseAmount,0))) end DistributeRate 
                            FROM CACHE_STAT WHERE {0}  Group By SortSorce ORDER BY {1}";

			string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));



			HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

			des.CurrentPage = currentpage;
			totalrecord = des.TotalCount;

			return des.GetSpecailPage();

		}

		/// <summary>
		/// 医院月统计,第一层的图片不区分采购类型
		/// </summary>
		/// <param name="where"></param>
		/// <param name="currentpage"></param>
		/// <param name="pagesize"></param>
		/// <param name="totalrecord"></param>
		/// <returns></returns>
		public DataTable ReportOfHospitalFirstLevel(object qeurymodel, string strwhere, int currentpage, int pagesize, out int totalrecord)
		{
			//入库率做修改 张雄 modify 2011.4.27
			string sql = @"SELECT DayTime,SUM(isnull(PurchaseAmount,0)) AS PurchaseAmountTotal,
                    
                         
                           SUM(isnull(sellAmount,0)) AS sellAmountTotal,
                           SUM(isnull(WarehouseAmount,0)) AS WareHouseAmountTotal,
                      
                           SUM(isnull(DistributeAmount,0)) AS DistributeAmountTotal,                          
                         
                        
                           SUM(isnull(ReturnAmount,0)) as ReturnAmountTotal
                           FROM CACHE_STAT WHERE {0} " + strwhere + " Group By DayTime ORDER BY {1}";

			string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));



			HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

			des.CurrentPage = currentpage;
			totalrecord = des.TotalCount;

			return des.GetSpecailPage();



		}

		/// <summary>
		/// 每月医院统计
		/// </summary>
		/// <param name="qeurymodel"></param>
		/// <param name="currentpage"></param>
		/// <param name="pagesize"></param>
		/// <param name="totalrecord"></param>
		/// <returns></returns>
		public DataTable DayTime_SortSorec_HospitalName_GroupBy(object qeurymodel, int currentpage, int pagesize, out int totalrecord)
		{
			//20110730 by:zhangxiong
			string sql = @"SELECT  HospitalName,DayTime,SortSorce,
                            SUM(isnull(PurchaseAmount,0)) AS PurchaseAmountTotal,
                            SUM(isnull(PurchaseCount,0)) AS PurchaseCountTotal,
                            SUM(isnull(WarehouseAmount,0)) AS WareHouseAmountTotal,
                            SUM(isnull(WarehouseCount,0)) AS WareHouseCountTotal,
                            SUM(isnull(DistributeAmount,0)) AS DistributeAmountTotal,

                            case when SUM(isnull(WarehouseAmount,0)) =0 then 0
	                            when SUM(isnull(PurchaseAmount,0)) = 0 then 0
	                            when convert(decimal(18,3),SUM(isnull(WarehouseAmount,0)) / SUM(isnull(PurchaseAmount,0))) >1 then 1
	                            else convert(decimal(18,3),SUM(isnull(WarehouseAmount,0)) / SUM(isnull(PurchaseAmount,0))) end WarehouseRate,  
                            SUM(isnull(SellAmount,0)) AS Profit,
                            SUM(isnull(PayOffAmount,0)) AS PayOffAmount,
                            SUM(isnull(ReturnAmount,0)) AS ReturnedGoods,
                            case when SUM(isnull(DistributeAmount,0)) = 0 then 0
                            when SUM(isnull(PurchaseAmount,0)) = 0 then 0 
                            when convert(decimal(18,3),SUM(isnull(DistributeAmount,0)) / SUM(isnull(PurchaseAmount,0))) > 1 then 1
                            else convert(decimal(18,3),SUM(isnull(DistributeAmount,0)) / SUM(isnull(PurchaseAmount,0))) end DistributeRate 

                            FROM CACHE_STAT WHERE {0} Group By DayTime,SortSorce,HospitalName Order By {1} ";

			string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));

			HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

			des.CurrentPage = currentpage;
			totalrecord = des.TotalCount;

			return des.GetSpecailPage();

		}

		/// <summary>
		/// 每月企业
		/// </summary>
		/// <param name="qeurymodel"></param>
		/// <param name="currentpage"></param>
		/// <param name="pagesize"></param>
		/// <param name="totalrecord"></param>
		/// <returns></returns>
		public DataTable DayTime_SortSorec_CompanyName_GroupBy(object qeurymodel, int currentpage, int pagesize, out int totalrecord)
		{
            //sql判断入库率，配送率大于1    by张雄
            string sql = @"SELECT  CompanyName,DayTime,SortSorce,

                SUM(DistributeAmount) AS DistributeAmountTotal,
                case when ISNULL(SUM(PurchaseAmount),0) = 0 then 0
                when CONVERT(decimal(18,3),SUM(WarehouseAmount) / SUM(PurchaseAmount)) > 1 then 1
                else CONVERT(decimal(18,3),SUM(WarehouseAmount) / SUM(PurchaseAmount)) end as WarehouseRate, 

                case when ISNULL(SUM(PurchaseAmount),0) = 0 then 0
                when CONVERT(decimal(18,3),SUM(DistributeAmount) / SUM(PurchaseAmount))> 1 then 1
                else CONVERT(decimal(18,3),SUM(DistributeAmount) / SUM(PurchaseAmount))end as DistributeRate,                 
                SUM(PurchaseAmount) AS PurchaseAmountTotal,
                SUM(PurchaseCount) AS PurchaseCountTotal,
                SUM(WarehouseAmount) AS WareHouseAmountTotal,
                SUM(WarehouseCount) AS WareHouseCountTotal,
                SUM(SellAmount) AS Profit,SUM(PayOffAmount) AS PayOffAmount,
                SUM(ReturnAmount) AS ReturnedGoods FROM CACHE_STAT 
                WHERE {0} and SortSorce in(0,1,2) Group By DayTime,SortSorce,CompanyName Order By {1} ";

			string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));

			HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

			des.CurrentPage = currentpage;
			totalrecord = des.TotalCount;

			return des.GetSpecailPage();
		}

        public DataTable DayTime_SortSorec_CompanyNameSC_GroupBy(object qeurymodel, int currentpage, int pagesize, out int totalrecord)
        {
            //判断如果入库率，配送率大于1   by张雄
            string sql = @"SELECT  CompanyName,DayTime,SortSorce,
                SUM(DistributeAmount) AS DistributeAmountTotal,
				SUM(PurchaseAmount) as PurchaseAmount2DaysAgoTotal, 
				SUM(PurchaseAmount) as PurchaseAmount4DaysAgoTotal,

				case when ISNULL(SUM(PurchaseAmount),0) =0 then 0
                when CONVERT(decimal(18,3),SUM(WarehouseAmount) / SUM(PurchaseAmount)) > 1 then 1 
                else CONVERT(decimal(18,3),SUM(WarehouseAmount) / SUM(PurchaseAmount)) end as WarehouseRate, 
                case when ISNULL(SUM(PurchaseAmount),0) = 0 then 0
                when CONVERT(decimal(18,3),SUM(DistributeAmount) / SUM(PurchaseAmount)) > 1 then 1
                else CONVERT(decimal(18,3),SUM(DistributeAmount) / SUM(PurchaseAmount)) end as DistributeRate, 

                SUM(PurchaseAmount) AS PurchaseAmountTotal,
                                       SUM(PurchaseCount) AS PurchaseCountTotal,SUM(WarehouseAmount) AS WareHouseAmountTotal,SUM(WarehouseCount) AS WareHouseCountTotal,
                           SUM(SellAmount) AS Profit,SUM(PayOffAmount) AS PayOffAmount,SUM(ReturnAmount) AS ReturnedGoods FROM CACHE_STAT_SC 
                           WHERE {0} and SortSorce in(0,1,2) Group By DayTime,SortSorce,CompanyName Order By {1} ";

            string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));

            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;

            return des.GetSpecailPage();
        }


		/// <summary>
		/// 区域统计
		/// </summary>
		/// <param name="qeurymodel"></param>
		/// <param name="currentpage"></param>
		/// <param name="pagesize"></param>
		/// <param name="totalrecord"></param>
		/// <returns></returns>
		public DataTable DayTime_SortSorec_AreaId_GroupBy(object qeurymodel, int currentpage, int pagesize, out int totalrecord)
		{
			//如果率修改 张雄 modify 2011.4.27

            

            string sqlWhere = "AND AreaID LIKE '22%'";
            string sql = @"SELECT DayTime,SUM(isnull(PurchaseAmount,0)) AS PurchaseAmountTotal,
                       
                           SUM(isnull(sellAmount,0)) AS sellAmountTotal,
                           SUM(isnull(WarehouseAmount,0)) AS WareHouseAmountTotal,
                        
                           SUM(isnull(DistributeAmount,0)) AS DistributeAmountTotal,                          
                        
                           
                           SUM(isnull(ReturnAmount,0)) as ReturnAmountTotal
                           FROM CACHE_STAT WHERE {0} " + sqlWhere + " Group By DayTime ORDER BY {1}";

			string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));

			HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

			des.CurrentPage = currentpage;

			totalrecord = des.TotalCount;

			return des.GetSpecailPage();
		}


		/// <summary>
		/// 企业月份统计
		/// 
		/// </summary>
		/// <param name="qeurymodel"></param>
		/// <param name="currentpage"></param>
		/// <param name="pagesize"></param>
		/// <param name="totalrecord"></param>
		/// <returns></returns>
        public DataTable DayTime_SortSorce_Company_GroupBy(object qeurymodel, string strwhere, int currentpage, int pagesize, out int totalrecord)
        {
            //配送率修改 张雄 modify 2011.4.27

            //判断入库率大于1就等于1

            string sql = @"SELECT DayTime,SUM(isnull(PurchaseAmount,0)) AS PurchaseAmountTotal,
                          
                           SUM(isnull(sellAmount,0)) AS sellAmountTotal,
                           SUM(isnull(WarehouseAmount,0)) AS WareHouseAmountTotal,
                         
                           SUM(isnull(DistributeAmount,0)) AS DistributeAmountTotal,                          
                        
                   
                           SUM(isnull(ReturnAmount,0)) as ReturnAmountTotal
                           FROM CACHE_STAT WHERE {0} " + strwhere + " Group By DayTime ORDER BY {1}";


            string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));

            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;

            return des.GetSpecailPage();

        }

        public DataTable DayTime_SortSorce_CompanySC_GroupBy(object qeurymodel, string strwhere, int currentpage, int pagesize, out int totalrecord)
        {
            //配送率修改 张雄 modify 2011.4.27
            //判断入库率，配送率大于1

            string sql = @"SELECT DayTime,SUM(isnull(PurchaseAmount,0)) AS PurchaseAmountTotal,
                         
                           SUM(isnull(sellAmount,0)) AS sellAmountTotal,
                           SUM(isnull(WarehouseAmount,0)) AS WareHouseAmountTotal,
                        
                           SUM(isnull(DistributeAmount,0)) AS DistributeAmountTotal,                          
                        
                       
                           SUM(isnull(ReturnAmount,0)) as ReturnAmountTotal

                           FROM CACHE_STAT_SC  
                           WHERE {0}" + strwhere + "  Group By DayTime,SortSorce Order By {1} ";


            string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));

            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;

            return des.GetSpecailPage();

        }

		/// <summary>
		/// 类型月份统计
		/// </summary>
		/// <param name="qeurymodel"></param>
		/// <param name="currentpage"></param>
		/// <param name="pagesize"></param>
		/// <param name="totalrecord"></param>
		/// <returns></returns>
		public DataTable DayTime_SortSore_SortName_GroupBy(object qeurymodel, int currentpage, int pagesize, out int totalrecord)
		{
			string sql = @"SELECT DayTime,SortSorce,SortId,max(SortName) as SortName,SUM(PurchaseAmount) AS PurchaseAmountTotal,SUM(PurchaseCount) AS PurchaseCountTotal,
                           SUM(WarehouseAmount) AS WareHouseAmountTotal,SUM(WarehouseCount) AS WareHouseCountTotal,
                           SUM(WarehouseAmount) / SUM(PurchaseAmount) AS WareHouseRate
                           FROM CACHE_STAT WHERE {0} Group By DayTime,SortSorce,SortId Order By {1} ";


			string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));

			HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);
			des.CurrentPage = currentpage;
			totalrecord = des.TotalCount;
			return des.GetSpecailPage();
		}
		/// <summary>
		/// 配送企业统计
		/// </summary>
		/// <param name="qeurymodel"></param>
		/// <param name="currentpage"></param>
		/// <param name="pagesize"></param>
		/// <param name="totalrecord"></param>
		/// <returns></returns>
        public DataTable DayTime_SortSore_CompanyPS_GroupBy(object qeurymodel, int currentpage, int pagesize, out int totalrecord)
        {
            //判断如果大于1
            string sql = @"SELECT CompanyName,SortSorce,
                            SUM(WarehouseAmount) as WarehouseAmountTotal,
                            SUM(PurchaseAmount) AS PurchaseAmountTotal,
                            SUM(PurchaseCount) AS PurchaseCountTotal,
                            SUM(DistributeAmount) AS DistributeAmountTotal,
                            SUM(DistributeCount) AS DistributeCountTotal,
                            case when ISNULL(SUM(PurchaseAmount),0) = 0 then 0
                            when CONVERT(decimal(18,3),SUM(WarehouseAmount) / SUM(PurchaseAmount)) > 1 then 1 
				            else CONVERT(decimal(18,3),SUM(WarehouseAmount) / SUM(PurchaseAmount)) end as WarehouseRate,
				            case when ISNULL(SUM(PurchaseAmount),0) = 0 then 0
                            when  CONVERT(decimal(18,3),SUM(DistributeAmount) / SUM(PurchaseAmount)) > 1 then 1
				            else CONVERT(decimal(18,3),SUM(DistributeAmount) / SUM(PurchaseAmount)) end as DistributeRate
                            FROM CACHE_STAT WHERE {0} and SortSorce in(0,1,2) 
                            Group By CompanyName,DayTime,SortSorce Order By {1} ";


            string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));

            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;

            return des.GetSpecailPage();
        }

        public DataTable DayTime_SortSore_CompanySC_GroupBy(object qeurymodel, int currentpage, int pagesize, out int totalrecord)
        {
            //判断如果 入库率，配送率大于1  by张雄
            string sql = @"SELECT CompanyName,SortSorce,
                SUM(PurchaseAmount) as PurchaseAmount2DaysAgoTotal, 
				SUM(PurchaseAmount) as PurchaseAmount4DaysAgoTotal,
                SUM(WarehouseAmount) as WarehouseAmountTotal,

                SUM(PurchaseAmount) AS PurchaseAmountTotal,SUM(PurchaseCount) AS PurchaseCountTotal,
                SUM(DistributeAmount) AS DistributeAmountTotal,SUM(DistributeCount) AS DistributeCountTotal,

                case when ISNULL(SUM(PurchaseAmount),0) = 0 then 0
                when CONVERT(decimal(18,3),SUM(WarehouseAmount) / SUM(PurchaseAmount)) > 1 then 1
                else CONVERT(decimal(18,3),SUM(WarehouseAmount) / SUM(PurchaseAmount)) end as WarehouseRate, 

                case when ISNULL(SUM(PurchaseAmount),0) =0 then 0
                when CONVERT(decimal(18,3),SUM(DistributeAmount) / SUM(PurchaseAmount)) > 1 then 1
                else CONVERT(decimal(18,3),SUM(DistributeAmount) / SUM(PurchaseAmount)) end as DistributeRate 

FROM CACHE_STAT_SC  
                           WHERE {0} and SortSorce in(0,1,2) Group By DayTime,CompanyName,SortSorce Order By {1} ";

            //
            string where = string.Format("1=1 {0}", HZ.Data.DAL_Helper.GetWhereCondition(qeurymodel, false));

            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(string.Format(sql, where, (qeurymodel as HZ.Data.QueryModel)["SortFields"].ToString()), pagesize);

            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;

            return des.GetSpecailPage();
        }
	}
}
